package ru.ifmo.ipimenov.ewf_svn.standalone.dao.impl;

import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import ru.ifmo.ipimenov.ewf_svn.standalone.dao.DocumentDao;
import ru.ifmo.ipimenov.ewf_svn.standalone.dao.StateDao;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.Document;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.User;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.Category;
import ru.ifmo.ipimenov.ewf_svn.standalone.model.db.State;
import ru.ifmo.ipimenov.ewf_svn.standalone.util.HibernateUtil;

import java.util.List;

/**
 * @author: Ilya Pimenov
 * Scartel Starlab company
 */
public class StateDaoHibernate implements StateDao {
    /**
     * Logger for all purposes
     */
    private static Log log = LogFactory.getLog(DocumentDaoHibernate.class);

    public List<State> list(Category category) {
        Session s = HibernateUtil.getSessionFactory().getCurrentSession();
        s.beginTransaction();

        List<State> l = s.createCriteria(State.class).add(Restrictions.eq("category", category)).list();
        s.getTransaction().commit();

        return l;
    }
}